package com.zhsecurity.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class LoginPageController {
    @Value("${zhsecurity.loginPage:/login/userNamePasswordLogin}")
    private String loginPageUrl;

    @GetMapping(value = "/loginPage")
    @ResponseStatus(code = HttpStatus.UNAUTHORIZED)
    public void loginPage(
            @RequestHeader(value = "X-Requested-With", required = false) String requestType,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        if (requestType == null) {//重定向自定义登录页面
            response.sendRedirect(loginPageUrl);
            return;
        }
    }
}
